<template>
  <div>
    <el-form label-position="right" label-width="100px">
      <el-row>
        <el-col :span="12">
          <el-form-item label="编码">
            <el-input v-model="formData.code"/>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="名称">
            <el-input v-model="formData.name"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="适用性别">
            <el-select v-model="formData.sex">
              <el-option label="不限" value="0"></el-option>
              <el-option label="男" value="1"></el-option>
              <el-option label="女" value="2"></el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="助记码">
            <el-input v-model="formData.helpCode"/>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="说明">
            <el-input v-model="formData.remark" type="textarea"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="注意事项">
            <el-input v-model="formData.attention" type="textarea"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

    </el-form>

<!--  <button class="el-button" @click="sendMsg">发送请求</button>-->
  </div>
</template>

<script>
export default {
  name: "GroupInfo",
  data() {
    return {
      formData: {
        code: '',
        name: '',
        sex: '0',
        helpCode: "",
        remark: '',
        attention: ''
      },
      headers:this.$cookies.get("token") != null ? this.$cookies.get("token") : '',
    }
  },
  mounted() {
    this.$bus.$on("clear",()=>{
      this.resetForm()
    })
    this.$bus.$on("edit_id",(data)=>{
      this.$axios.get(`/api/checkgroup/getBaseInfo.do?id=${data}`,{
        headers:this.headers
      }).then((res)=>{
        if(!res.data.flag){
          this.$message.error("查询基本信息出错啦")
        }else {
          this.formData = res.data.data
          this.$store.dispatch("setFormData",this.formData)
        }
      })
    })
    /*this.$bus.$on("post",function (data){
      console.log(data)
    })*/
  },
  beforeDestroy() {
    this.$bus.$off()
  },
  updated() {
    // console.log(JSON.stringify(this.formData))
    this.$store.dispatch("setFormData",this.formData)
  },
  methods:{

    // 重置表单
    resetForm() {
      this.formData = {}
    },

  },

}
</script>

<style scoped>

</style>